package versionControl.aspectj.library;

import versionControl.aspectj.library.Versioned;

public aspect Update {
	/*
	 * Upon any versioned object's field change, if the version to 
	 * change is the most current one, update the relevant version with the change
	 */
	void around(Versioned obj) : set(* *.*) && target(obj) && withincode(* *.*(..)) 
	&& !within(versionControl.aspectj.library.*) && if (obj.getVersionID() != obj.getLatestVersionID()){
		// Updates the given object version by invoking the relevant set method by reflection 
		// on a relevant version
		String methodName = thisJoinPoint.getSignature().getName();
		Object args[] = thisJoinPoint.getArgs();			
		obj.UpdateField(obj.getVersionID(),methodName,args);
	}
}